package com.podigua.example.modular;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringJoiner;


/**
 * 应用实例
 *
 * @author podigua
 * @date 2024/03/04
 */
public class ModularExampleApplication extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        List<String> raws = getParameters().getRaw();
        Map<String, String> named = getParameters().getNamed();
        HBox root = new HBox();
        TextArea text = new TextArea();
        StringJoiner joiner = new StringJoiner(System.lineSeparator());
        Properties properties = System.getProperties();
        if (raws != null && !raws.isEmpty()) {
            joiner.add("参数信息:");
            for (int index = 0; index < raws.size(); index++) {
                joiner.add("参数" + (index + 1) + ":" + raws.get(index));
            }
            joiner.add("\n");
        }
        if (named != null && !named.isEmpty()) {
            named.forEach((k,v)->{
                joiner.add("参数" +k + ":" + v);
            });
        }
        joiner.add("\n内存信息:");
        long maxMemory = Runtime.getRuntime().maxMemory();
        joiner.add("max-memory:" + maxMemory);
        joiner.add("\n环境变量:");
        properties.forEach((k, v) -> {
            joiner.add(k + " : " + v);
        });
        text.setText(joiner.toString());
        text.prefWidthProperty().bind(root.widthProperty());
        text.prefHeightProperty().bind(root.heightProperty());
        root.getChildren().add(text);
        stage.setScene(new Scene(root, 800, 600));
        stage.setTitle("模块化");
        stage.show();
    }
}
